package com.qf.springboot2203.config;

import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SihroConfig {
    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition(){

        DefaultShiroFilterChainDefinition defaultShiroFilterChainDefinition = new DefaultShiroFilterChainDefinition();

        defaultShiroFilterChainDefinition.addPathDefinition("/user/login","anon");

        defaultShiroFilterChainDefinition.addPathDefinition("/A.html","roles[admin]");

        defaultShiroFilterChainDefinition.addPathDefinition("/swagger-ui.html","anon");

        defaultShiroFilterChainDefinition.addPathDefinition("/webjars/springfox-swagger-ui/**","anon");
        defaultShiroFilterChainDefinition.addPathDefinition("/null/swagger-resources/configuration/ui","anon");
        defaultShiroFilterChainDefinition.addPathDefinition("/swagger-resources/**","anon");
        defaultShiroFilterChainDefinition.addPathDefinition("/v2/api-docs","anon");

        defaultShiroFilterChainDefinition.addPathDefinition("/error","anon");



        //默认所有都拦截 ，个别的可以放在上面卸annon
        defaultShiroFilterChainDefinition.addPathDefinition("/**","authc");

        return defaultShiroFilterChainDefinition;
    }
    @Bean
    public Realm realm(){
         CustomRealm customRealm = new CustomRealm();

   //  HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();

   //  hashedCredentialsMatcher.setHashAlgorithmName("md5");

   //  hashedCredentialsMatcher.setHashIterations(1024);

   //  customRealm.setCredentialsMatcher(hashedCredentialsMatcher);

       return customRealm;
    }
}
